<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Event/classes/PhpFox_ComponentView.class.php, $Author:  $ */



/** Component for viewing events
 * @version $Id: PhpFox_ComponentView.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.event
 *
 */
class PhpFox_Mod_Event_ComponentView extends BaseComponent
{
    function process()
    {
        $oEventItem = $this->_oModule->getItem('Event');
        /* @var $oEventItem PhpFox_Mod_Event_ItemEvent */
        $oEventService = $this->_oModule->getService('Event');
        /* @var $oEventService PhpFox_Mod_Event_ServiceEvent */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oText = App::newObject('Text');
        /* @var $oText Text */
        $oTpl = $this->_oModule->getTemplate();
        $oReq = &App::getRequest();
        $aOut = array();

        $oSecurityService->checkPerm('events', array('read_only', 'full'));
        $oSecurityService->checkAccess('events');
        $bIsStaff = $oSecurityService->isStaff();
        $bIsAdmin = $oSecurityService->isAdmin();
        $iId = $oReq->getInt('id');
        $sUser = $oSecurityService->getCurrentUserLogin();

        if (!$iId)
        {
            App::gotoUrl('public.event.main');
        }

        if ($oReq->get('act') == 'delete')
        {
        	$oEventItem->load($iId);
        	if ((($oEventItem->aData['user'] == $sUser) && $oSecurityService->checkPerm('events', array('full'), false)) || $bIsStaff)
        	{
        	    $oEventService->deleteEvent($iId);
                App::gotoUrl('public.event.main');
        	}
            App::gotoUrl('public.event.view', array('id' => $iId));
        }

        if ($oReq->get('act') == 'feature')
        {
            if ($bIsStaff)
            {
                $oEventItem->load($iId);
                $oEventItem->aData['feature'] = ($oEventItem->aData['feature'] == 0) ? 1 : 0;
                $oEventItem->update(array('feature'));
            }
            App::gotoUrl('public.event.view', array('id' => $iId));
        }

        if ($oReq->get('forward') == 1)
        {
            $oEventItem->load($iId);

            $oTxt = &App::newObject('Text');

            $_SESSION['compose']['subject'] = 'EVENTS: '. $oTxt->preParseText($oEventItem->aData['title']);
            $sMessage = ''. App::format('Mod_Event.check_out_this_event') .':
 --------- '. App::format('Mod_Event.events_post') .' --------------------------------------
 [quote="'.$oEventItem->aData['user'].'"]
 '. $oTxt->preParseText($oEventItem->aData['text']) .'
 [/quote]';
            $_SESSION['compose']['message'] = $oTxt->preParseText($sMessage);
            App::gotoUrl('public.account.messages.compose');
        }


        if (!$oEventItem->load($iId))
        {
            App::gotoUrl('public.event.main');
        }

        $oEventItem->aData['views']++;
        $oEventItem->update(array('views'));

        $aItem = $oEventItem->aData;

        if ($aItem['private'] == 2 AND !$bIsStaff AND !$bIsAdmin AND App::getUser('user') != $aItem['user'])
        {
			$oFriendsService = &App::getModuleService('Account', 'Friends');

			if ( $oFriendsService->checkIsFriend(App::getUser('user'), $aItem['user']) == 0 )
			{
            	App::gotoUrl('public.event.main');
            }
        }

        $aItem['time'] = mktime(0, 0, 0, $aItem['month'], $aItem['day'], $aItem['year']);
		$oTpl->assignSrc('aItem', $aItem);

        $oTpl->assign(array(
        	'sUImageUrl' => App::getParam('user.pic.url'),
        	'bStaff'     => $bIsStaff,
        	'bAdmin'     => $bIsAdmin,
        	'bCanEdit'   => $oSecurityService->checkPerm('events', array('full'), false),
        	'sCurrUser'  => $sUser,
        	'sFtext'     => $oText->parseText($oEventItem->aData['text']),
        	'sTitle'     => htmlspecialchars($oEventItem->aData['title']),
        ));

        return $oTpl->fetch('EventView.html');
    }
}
?>